<!DOCTYPE html>
<html lang="en">

<head>
    <#include "/jh/admin/components/meta.html" />
    <title>排课信息 ${metaTitleSuffix!}</title>
    <#include "/jh/admin/components/stylesheets.html" />
</head>

<body>
    <div id="app">
        <el-container>
            <#assign menuIndex="1-2" />
            <#include "/jh/admin/components/menu.html" />
            <el-container>
                <#include "/jh/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-row>
                            <el-col :span="12" style="display: flex; align-items: center;">
                                <div class="title theme-color1">排课</div>
                            </el-col>
                            <el-col :span="12">
                                <div class="operations">
                                    <#if hasPermission('ARR_ADD')>
                                        <el-button type="success" size="small" @click="add" ${hasEditPermission('ARR_ADD')}><i class="el-icon-plus"></i>添加</el-button>
                                        <el-button type="success" size="small" @click="addMultiTopics" ${hasEditPermission('ARR_ADD')}><i class="el-icon-plus"></i>批量添加</el-button>
                                        <el-button type="success" size="small" @click="onDownload()" ><i class="el-icon-download"></i>下载</el-button>
                                    </#if>
                                </div>
                            </el-col>
                        </el-row>
                        <div class="options">
                            <el-date-picker v-model="date" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" @change="onDateChange" unlink-panels="true">
                            </el-date-picker>
                            <el-select v-model="schoolId" placeholder="校区" clearable @change='onSchoolChanged'>
                                <el-option v-for="item in schools" :key="item.id" :label="item.name" :value="item.id">
                                </el-option>
                            </el-select>
                            <el-select v-model="staffId" placeholder="老师" clearable @change='onStaffChanged'>
                                <el-option v-for="item in staffs" :key="item.id" :label="item.englishName" :value="item.id">
                                    {{item.englishName}} <span style="color: gray">{{item.name}}</span>
                                </el-option>
                            </el-select>
                            <el-select v-model="courseId" placeholder="课程" clearable @change='onCourseChanged'>
                                <el-option v-for="item in courses" :key="item.id" :label="item.name" :value="item.id">
                                </el-option>
                            </el-select>
                            <el-select v-model="tag" placeholder="级别" clearable @change='onTagChanged'>
                                <el-option v-for="item in tags" :key="item" :label="item" :value="item">
                                </el-option>
                            </el-select>
                            <el-select v-model="joinCourse" placeholder="选课情况" clearable @change='onCourseJoinChanged'>
                                <el-option label="有选课" value="0"></el-option>
                                <el-option label="无选课" value="1"></el-option>
                            </el-select>
                        </div>
                        <el-table ref="multipleTable" :data="list" tooltip-effect="dark" style="width: 100%" highlight-current-row>
                            <el-table-column prop="date" label="日期" sortable>
                            </el-table-column>
                            <el-table-column prop="time" label="时间" sortable>
                            </el-table-column>
                            <el-table-column prop="name" label="课程名称" sortable show-overflow-tooltip>
                                <template slot-scope="scope">
                                    <span v-if='scope.row.isHaveBlackListStudent == 1' style="color: red">*</span>{{scope.row.name}}
                                </template>
                            </el-table-column>
                            <el-table-column prop="topic" label="主题" sortable>
                            </el-table-column>
                            <el-table-column prop="teacher" label="老师" sortable>
                                <template slot-scope="scope">
                                    <span v-if="scope.row.teacherEnglishName != null && scope.row.teacherEnglishName != ''">{{ scope.row.teacherEnglishName }}</span>
                                    <span v-else-if="scope.row.teacher != null && scope.row.teacher != ''">{{ scope.row.teacher }}</span>
                                    <span v-else-if="scope.row.partTimeTeacherName != null && scope.row.partTimeTeacherName != ''">{{ scope.row.partTimeTeacherName }} (兼职)</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="limit" label="已选 / 总数" sortable>
                                <template slot-scope="scope">
                                    <span v-if="scope.row.limit == 0">{{ scope.row.joinCount }} / 不限</span>
                                    <span v-else>{{ scope.row.joinCount }} / {{ scope.row.limit }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="schoolName" label="校区" sortable>
                            </el-table-column>
                            <el-table-column prop="classroom" label="教室" sortable>
                            </el-table-column>
                            <el-table-column prop="isHide" label="是否隐藏" sortable width='50px'>
                                <template slot-scope="scope">
                                    <span v-if="scope.row.isHide == 1">是</span>
                                    <span v-if="scope.row.isHide == 0">否</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="isCount" label="扣课时" sortable width='50px'>
                                <template slot-scope="scope">
                                    <span v-if="scope.row.isCount == 1">是</span>
                                    <span v-if="scope.row.isCount == 0">否</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="isOnClass" label="已上课" sortable width='50px'>
                                <template slot-scope="scope">
                                    <span v-if="scope.row.isOnClass == 1">是</span>
                                    <span v-if="scope.row.isOnClass == 0">否</span>
                                </template>
                            </el-table-column>
                            <el-table-column fixed="right" label="操作" width="180">
                                <template slot-scope="scope">
                                    <#if hasPermission('ARR_ADD_STUDENT')>
                                        <el-button @click="select(scope.row)" type="text" size="small" ${hasEditPermission('ARR_ADD_STUDENT')}>选课学生</el-button>
                                    </#if>
                                    <#if hasPermission('ARR_EDIT')>
                                        <el-button @click="edit(scope.row)" type="text" size="small" ${hasEditPermission('ARR_EDIT')}>编辑</el-button>
                                    </#if>
                                    <#if hasPermission('ARR_DEL')>
                                        <el-button @click="del(scope.row)" type="text" size="small" style="color: red;" ${hasEditPermission('ARR_DEL')}>删除</el-button>
                                    </#if>
                                </template>
                            </el-table-column>
                        </el-table>
                        <#include "/jh/admin/components/page.html" />
                        <p>课时:${courseTime!0}分钟(约${courseTime/60}小时)</p>
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <#include "/jh/admin/components/footer.html" />
    </div>
    <#include "/jh/admin/components/scripts.html" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/json5/0.5.1/json5.min.js"></script>
    <script type="text/javascript" src="/jh/admin/components/pageJs.js"></script>
    <script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data() {
            return {
                list: [],
                joinCourse: '${joinCourse!""}',
                date: ['${startDate!}', '${endDate!}'],
                schools: JSON.parse('${schools!""}'),
                staffs: JSON.parse('${staffs!""}'),
                courses: JSON.parse('${courses!""}'),
                tags: [],
                schoolId: null,
                staffId: null,
                courseId: null,
                tag: null,
            }
        },
        mounted: function() {
            var str = '${items!}'
            if (str != '') {
                this.list = JSON5.parse('${items!}')
            }
            var tagStr = '${tags!}';
            if (tagStr != '') {
                this.tags = tagStr.split(",");
                this.tags.pop();
            }
            var schoolId = '${schoolId!""}'
            if (schoolId != '') {
                this.schoolId = Number(schoolId);
            }
            var staffId = '${staffId!""}'
            if (staffId != '') {
                this.staffId = Number(staffId);
            }
            var courseId = '${courseId!""}'
            if (courseId != '') {
                this.courseId = Number(courseId);
            }
            var tag = '${tag!""}'
            if (tag != '') {
                this.tag = tag;
            }
        },
        methods: {
            onDownload(){
                goDownload();
            },
            add() {
                window.location.href = "/jh/admin/arrange/info";
            },
            addMultiTopics() {
                window.location.href = "/jh/admin/arrange/addArrange";
            },
            select(item) {
                window.location.href = "/jh/admin/arrange/addStudentToArrange?arrangeId=" + item.id;
            },
            edit(item) {
                // window.location.href = "/jh/admin/arrange/info?arrangeId=" + item.id;
                window.open("/jh/admin/arrange/info?arrangeId=" + item.id)
            },
            del(item) {
                var self = this;
                confirm("确认删除？请谨慎操作", "确认", function() {
                    var param = Qs.stringify({
                        arrangeId: item.id
                    });
                    loading()
                    axios({
                            url: '/jh/admin/arrange/delete',
                            method: 'post',
                            data: param,
                            headers: {
                                'Content-Type': 'application/x-www-form-urlencoded'
                            }
                        })
                        .then(function(response) {
                            if (response.data.status == 200) {
                                endLoading();
                                window.location.reload()
                                // msg("登录成功");
                            } else {
                                endLoading();
                                msg(response.data.msg);
                                console.log(response.data);
                            }
                        })
                        .catch(function(error) {
                            endLoading();
                            msg("删除失败");
                            console.log(error);
                        });
                })
            },
            onCourseJoinChanged() {
                var keys = [
                    { key: 'joinCourse', value: this.joinCourse }
                ]
                goPage(1, keys)
            },
            onDateChange(val) {
                var keys = [
                    { key: 'startDate', value: val[0] },
                    { key: 'endDate', value: val[1] }
                ]
                goPage(1, keys)
                // window.location.href = "/jh/admin/arrange/list?startDate=" + val[0] + "&endDate=" + val[1];
            },
            onSchoolChanged() {
                var keys = [
                    { key: 'schoolId', value: this.schoolId }
                ]
                goPage(1, keys)
            },
            onStaffChanged() {
                var keys = [
                    { key: 'staffId', value: this.staffId }
                ]
                goPage(1, keys)
            },
            onCourseChanged() {
                var keys = [
                    { key: 'courseId', value: this.courseId }
                ]
                goPage(1, keys)
            },
            onTagChanged() {
                var keys = [
                    { key: 'tag', value: this.tag }
                ]
                goPage(1, keys)
            },
            onPageChange(val) {
                // console.log('当前页: {val}' + val);
                goPage(val)
            }
        }
    })
    </script>
    <style type="text/css">
    .title {
        font-size: 18px;
        font-weight: bold;
    }

    .operations {
        text-align: right;
    }

    .options {
        display: flex;
        align-items: center;
        padding-top: 1rem;
    }
    </style>
    <#include "/jh/admin/components/msg.html" />
</body>

</html>